package api

import (
	"net/http"
	"playbook/ginsvr/src/orm/dict"

	"github.com/gin-gonic/gin"
)

//查询数据字典中的所有参数
//r.POST("getAllParamInDict", api.GetAllParamInDict)
func GetAllParamInDict(c *gin.Context) {
	res := dict.GetAllParams()
	c.JSON(http.StatusOK, res)
}

//添加查询数据字典
//r.POST("getParamInDictByCondiction", api.GetParamInDictByCondiction)
func GetParamInDictByCondiction(c *gin.Context) {

	var condition map[string]interface{}
	if c.Bind(&condition) == nil {
		resp := dict.GetParamByCondiction(condition)
		c.JSON(http.StatusOK, resp)
	}
}

//r.POST("addParamInDict", func(c *gin.Context)
func AddParamInDict(c *gin.Context) {
	var param map[string]interface{}
	if c.Bind(&param) == nil {
		resp := dict.AddParamInDict(param)
		c.JSON(http.StatusOK, resp)
	}
}

//r.POST("getParamInDictById",
func GetParamInDictById(c *gin.Context) {

	var param map[string]interface{}
	if c.Bind(&param) == nil {
		resp := dict.GetParamdefById(param["parameterid"].(string), "")
		c.JSON(http.StatusOK, resp)
	}
}

//r.POST("updateParamdef"
func UpdateParamdef(c *gin.Context) {
	var param map[string]interface{}
	if c.Bind(&param) == nil {
		resp := dict.UpdateParamdef(param)
		c.JSON(http.StatusOK, resp)
	}
}

//r.POST("deleteParamdefById"
func DeleteParamdefById(c *gin.Context) {
	var param map[string]interface{}
	if c.Bind(&param) == nil {
		resp := dict.DeleteParamdefById(param["parameterid"].(string))
		c.JSON(http.StatusOK, resp)
	}
}

//r.POST("getParamByName",
func GetParamByName(c *gin.Context) {
	var paramName struct {
		ParamName string `json:"paramName" binding:"required"`
	}
	if c.Bind(&paramName) == nil {
		res := dict.GetParamDefTreeByName(paramName.ParamName)
		c.JSON(http.StatusOK, res)
	}
}
